package com.woniu.shop.rabibit;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class ConfirmProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private RabbitConfirm rabbitConfirm;
    @PostConstruct
    public void init(){
        rabbitTemplate.setConfirmCallback(rabbitConfirm);
        // true 表示消息未到达队列时会把消息返回给生产者；false会直接丢弃消息
        rabbitTemplate.setMandatory(true);
        rabbitTemplate.setReturnCallback(rabbitConfirm);
    }

    public void producerConfirm(Integer id) {
        rabbitTemplate.convertAndSend("exchange-application","queue-application",id);
    }
}
